package hot;

import java.util.*;

public class Num49 {
    public List<List<String>> groupAnagrams(String[] strs) {
            Map<String, ArrayList<String>> map = new HashMap<>();
            for(String s : strs) {
                char[] chars = s.toCharArray();
                Arrays.sort(chars);
                String str = new String(chars);
                ArrayList<String> list = map.getOrDefault(str,new ArrayList<String>());
                list.add(s);
                map.put(str,list);
            }
            return new ArrayList<List<String>>(map.values());
    }
}
